package com.wgzx.modbus.entity.request;


import com.wgzx.modbus.entity.ModbusReq;
import lombok.Getter;

import static com.wgzx.modbus.constant.FunctionCode.READ_COILS;
import static com.wgzx.modbus.util.ModbusUtil.validateRange;

/**
 * 读线圈 <br/>
 * 功能码：0x01 <br/>
 * 起始地址：2个字节0x0000至0xFFFF <br/>
 * 线圈数量：2个字节0x01至0x07D0 <br/>
 *
 * @author gexin
 */
@Getter
public class ReadCoilsRequest extends ModbusReq {

    public ReadCoilsRequest(int startingAddress, int quantityOfCoils) {
        super(READ_COILS, startingAddress, quantityOfCoils);
        validateRange(startingAddress, "startingAddress", 0x00, 0xFFFF);
        validateRange(quantityOfCoils, "quantityOfCoils", 0x01, 0x07D0);
    }

    @Override
    public String toString() {
        return "ReadCoilsRequest{" + "startingAddress=" + address + ", quantityOfCoils=" + value + '}';
    }
}
